<?php
header('Access-Control-Allow-Origin:*');
$allowms = ['POST', 'GET'];
$m = $_SERVER['REQUEST_METHOD'];
if (in_array($m, $allowms)) {
    switch ($m) {
        case 'GET':
            $d = new pdo('mysql:host=localhost;dbname=zgdb;port=3306;charset=utf8', 'root', '', []);
            $st = $d->prepare('select id,name,score from t_user order by id desc');
            $st->execute();
            $rs = $st->fetchAll(PDO::FETCH_ASSOC);
            echo json_encode(['code' => 200, 'msg' => '查询成功', 'data' => $rs], JSON_UNESCAPED_UNICODE);
            break;
        case 'POST':

            break;

        case 'PUT':

            break;

        case 'DELETE':

            break;
        default:
            die('api接口请求方法不支持');
    }
} else {

    echo json_encode(['code' => 400, 'msg' => '接口请求方法不支持', 'data' => ''], JSON_UNESCAPED_UNICODE);
    die();
}